import store from '@/store/index';

/**
 * 验证权限
 * @param {*} list Array 校验的数组
 * @param {*}
 * @returns  Boolean / true or false
 */
export function checkAuth(list = []) {
  if (list?.length > 0) {
    const permissionSet = store?.getters?.['permission/permissionSet'];
    const hasAuth = list.some((item) => {
      return permissionSet.has(item);
    });
    return hasAuth;
  } else {
    return false;
  }
}

/**
 * 验证角色权限
 * @param {*} list Array 校验的数组
 * @param {*}
 * @returns  Boolean / true or false
 */
export function checkRole(list = []) {
  if (list?.length > 0) {
    const rolesSet = store?.getters?.['user/roleMarkSet'];
    const hasRole = list.some((item) => {
      return rolesSet.has(item);
    });
    return hasRole;
  } else {
    return false;
  }
}
